
var city = "张家口";

function a()
{

    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {


            var json = JSON.parse(xmlhttp.responseText);

            console.log(json);

            //城市
            document.querySelector("#city").innerHTML = json.basic.city;




            //获取1-7天

            for(var i=0;i<json.daily_forecast.length;i++){
                //时间
                var a = document.querySelectorAll(".sky .a");
                //console.log(a[i]);
                a[i].innerHTML = json.daily_forecast[i].date;
                //console.log(json.daily_forecast[i].date);

                //天气
                var b = document.querySelectorAll(".sky .b");
                b[i].innerHTML = json.daily_forecast[i].cond.txt_d;
                //console.log(json.daily_forecast[i].cond.txt_d);

                //最高温度
                var sp_1 = document.querySelectorAll(".sky .sp-1");
                sp_1[i].innerHTML = json.daily_forecast[i].tmp.max+"℃";
                //console.log(sp_1[i]);
                //console.log(json.daily_forecast[i].tmp.max);

                //最低温度
                var sp_2 = document.querySelectorAll(".sky .sp-2");
                sp_2[i].innerHTML = json.daily_forecast[i].tmp.min+"℃";
                //console.log(json.daily_forecast[i].tmp.min);

                //风力
                var sp_3 = document.querySelectorAll(".sky .sp_1");
                sp_3[i].innerHTML = json.daily_forecast[i].wind.sc+"级";
                //console.log(json.daily_forecast[i].wind.sc);


            }



            var h1 = document.querySelectorAll(".c .h");
            for(var j=0;j<h1.length;j++) {

                //时间段时间


                h1[j].innerHTML = json.hourly_forecast[j].date;
                console.log(json.hourly_forecast[j].date);

                //时间段的温度
                var s_1 = document.querySelectorAll(".li .s_1");
                console.log(s_1);
                s_1[j].innerHTML = json.hourly_forecast[j].tmp;
                console.log(json.hourly_forecast[j].tmp);


                //时间段的风向
                var p1 = document.querySelectorAll(".li .p1");
                console.log(p1);
                p1[j].innerHTML = json.hourly_forecast[j].wind.dir;
                console.log(json.hourly_forecast[j].wind.dir);


                //时间段的风力
                var s1 = document.querySelectorAll(".li .s1");
                console.log(s1);
                s1[j].innerHTML = json.hourly_forecast[j].wind.sc;
                console.log(json.hourly_forecast[j].wind.sc);

            }



            // 紫外线指数
            document.querySelector("#brf").innerHTML = json.suggestion.uv.brf;

            document.querySelector("#txt").innerHTML = json.suggestion.uv.txt;



            //感冒指数
            document.querySelector("#brf1").innerHTML = json.suggestion.flu.brf;

            document.querySelector("#txt1").innerHTML = json.suggestion.flu.txt;


            //旅游指数
            document.querySelector("#brf2").innerHTML = json.suggestion.trav.brf;

            document.querySelector("#txt2").innerHTML = json.suggestion.trav.txt;


            //穿衣指数
            document.querySelector("#brf3").innerHTML = json.suggestion.drsg.brf;

            document.querySelector("#txt3").innerHTML = json.suggestion.drsg.txt;



            //洗车指数
            document.querySelector("#brf4").innerHTML = json.suggestion.cw.brf;

            document.querySelector("#txt4").innerHTML = json.suggestion.cw.txt;


            //空气污染指数
            document.querySelector("#brf5").innerHTML = json.suggestion.air.brf;

            document.querySelector("#txt5").innerHTML = json.suggestion.air.txt;


            //console.log(xmlhttp.responseText);
            //document.querySelector('#mydiv').innerHTML=xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET","https://bird.ioliu.cn/weather?city=" + city,true);
    xmlhttp.send();
}
a();


document.querySelector("#ipt").addEventListener("change",function(){
    console.log(this.value);
    //赋值城市名

    city = this.value;
    //执行获取天数的函数
    a();
});